package com.wx.gof.pattern.creational.prototype;



import java.util.Date;


/**
 * @ClassName Pig
 * @Author wx
 * @Description 猪-浅拷贝
 * @Date 2018-12-07-23:42
 */
//@Data 次注解会导致clone失效 复制出来的引用对象指向的还是原对象
public class Pig implements Cloneable{
    private String name;
    private int age;
    private Date now;


    public Pig(String name, int age, Date now) {
        System.out.println("创建对象");
        this.name = name;
        this.age = age;
        this.now = now;
    }


    public String getName() {
        return name;
    }

    public void setName(String name) {
        this.name = name;
    }

    public int getAge() {
        return age;
    }

    public void setAge(int age) {
        this.age = age;
    }

    public Date getNow() {
        return now;
    }

    public void setNow(Date now) {
        this.now = now;
    }

    @Override
    public String toString() {
        return "Pig{" + "name='" + name + '\'' + ", age=" + age + ", now=" + now + '}' + super.toString();
    }

    /**
     * @methodName: clone
     * @author: wx
     * @description: 拷贝方法
     * @param
     * @date: 2018/12/8
     * @return: java.lang.Object
     */
    @Override
    protected Object clone() throws CloneNotSupportedException {
        System.out.println("复制对象");
        return super.clone();
    }
}
